package kr.ltkblue;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;

public class UrlConn2 {
	public static void main(String[] args) {
		  URL url         = null;
		  StringBuffer sbHtml     = new StringBuffer();
		  InputStream is       = null;
		  BufferedReader br      = null;
		  String data        = null;
		  HttpURLConnection hurlc   = null;
		  String keyword       = "������û";
		  URLConnection urlc     = null;

		  try{
		   String strKeyword = URLEncoder.encode(keyword,"UTF-8");
		   String strUrl   = "http://www.googleapis.com/upload/drive/v2/files?uploadType=media";
		   // URL�� ǥ���ϴ� String���� URLŬ���� ��ü��.
		   url = new URL(strUrl);
		   urlc = (HttpURLConnection)url.openConnection();
		   urlc.setRequestProperty("User-Agent","Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.2)");
		   urlc.setRequestProperty("Accept-Language", "UTF-8");
		   urlc.setRequestProperty("Method", "POST");
		   urlc.setRequestProperty("Accept", "image/gif, image/xxbitmap, image/jpeg, image/pjpeg,application/xshockwaveflash, application/vnd.msexcel,application/vnd.mspowerpoint, application/msword, */*");
		   urlc.setRequestProperty("Accept-Charset","UTF-8");
//		   urlc.setRequestProperty("Referer","http://www.naver.com/");
		   urlc.setConnectTimeout(30000);
		   urlc.setReadTimeout(30000);


		   //�Է� ��Ʈ���� �̿��Ͽ� BufferedReader Ŭ���� ��ü�� ��.
		   br = new BufferedReader(new InputStreamReader(urlc.getInputStream(), "UTF-8"));

		   //�Է� ��Ʈ������ �����Ͱ� �Ϸ�ɶ����� �����͸� �о ȭ�鿡 ǥ��.
		   while((data = br.readLine()) != null ){
		    sbHtml.append(data);
		   }
System.out.println(sbHtml);
		  }catch (Exception e) {
		   // TODO: handle exception
		   e.printStackTrace();
		  }
		 }
		 public static String removeHtml(String str){
		  if(str==null)return "";
		  return str.replaceAll("<(/)?([a-zA-Z]*)(\\s[a-zA-Z]*=[^>]*)?(\\s)*(/)?>", "");
		 }
}
